var path = window.location.href;
var param = path.split("?")
var a=param[1].split("=")
var tiger=a[1]
var ooo=tiger.split(",")
var t=0
for (i=0;i<ooo.length;i++){
    if (!ooo[i]==""){
        t++
    }
}
var id=ooo[t-1]
var namee=ooo[t-2]
var numArrr = [];

for (i=0;i<t-2;i++){
    numArrr.push(ooo[i])
}

$(function() {
    var myclick = $('#my_submit');
    var tables = $('#teb_lsit');
    i=1
    myclick.click(function () {
        i++
        if(i>9){
            layer.msg('输入超限!', {icon: 6, time: 1000});
            return false
        }
        if(i==1){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id1" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==2){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id2" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==3){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id3" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==4){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id4" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==5){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id5" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==6){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id6" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==7){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id7" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==8){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id8" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==9){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id9" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==10){
            var a= i+1
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+a+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text id" name="id10" style="width:85px;" placeholder="请输入比率" id="id" required>%</div></div>');
            add_list.appendTo(tables);
        }
    })
    //需要知道数据的数量，还有input的值集合
    var cont =t-3
    var input=numArrr
    $("#rich_text").val(decodeURI(namee))
    $("#discount_rate_id").val(input[0])
    for (var i=0;i<=cont-1;i++) {
        var con=i+2
        if (i==0){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[1]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }else if (i==1){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[2]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==2){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[3]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==3){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[4]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==4){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[5]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==5){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[6]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==6){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[7]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==7){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[8]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }else if(i==8){
            var add_list = $('<div class="row cl"><label class="form-label col-sm-2">折扣率'+con+'：</label><div class="formControls col-sm-9" ><input type="text" class="input-text discount_rate_id" value="'+input[9]+'" placeholder="请输入比率" name="articletitle" style="width:85px;" disabled>%</div></div>');
            add_list.appendTo(tables);
        }
    }
})
// 保存按钮
$("#form-member").validate({
    rules: {
        id1:"idCheck",
        id2:"idCheck",
        id3:"idCheck",
        id4:"idCheck",
        id5:"idCheck",
        id6:"idCheck",
        id7:"idCheck",
        id8:"idCheck",
        id9:"idCheck",
        id10:"idCheck",
    },
    //提交表单数据
    submitHandler:function(form){
        layer.confirm('是否要生效您配置的品类折扣价',function(index){
            //提交
            var numArr = [];
            var cesi =$("#id").val();
            if (cesi==undefined){
                layer.msg('操作成功!', {icon: 6, time: 1000});
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
                return;
            }
            $('.id').each(function(){
                numArr.push($(this).val());
            });
            var kill=numArr.join(",")
            var quzhi=JSON.parse(web.readCookie("loginData"))
            var user_data = {
                DiscountId:id,
                LastModifiedBy:quzhi.user.user_ID,
                value:kill,
            }
            console.log(user_data)
            var arr=kill+","+numArrr
            var uuu=[]
            //将numArrr 已存在的值变为数组
            for(i=0;i<numArrr.length;i++){
                var u=parseFloat(numArrr[i])
                uuu.push(u)
            }
            //将numArr 新的值变为数组
            if (numArr.length!=0){
                for (i=0;i<numArr.length;i++){
                    var s=parseFloat(numArr[i])
                    uuu.push(s)
                }
            }
            var ttt=uuu.sort()
            for(var i=0;i<ttt.length;i++) {
                if (ttt[i]==ttt[i + 1]) {
                    return layer.msg('存在重复值!!!'+ttt[i]+'已重复', {icon: 6, time: 3000});
                }
            }
            var succCallBack = function (data, status, response) {
                console.log(data);
                if(data.errorCode=="0") {
                    layer.msg('操作成功!', {icon: 6, time: 1000});
                    parent.isEdit = true;
                    parent.queryDataFn();
                    setTimeout( function () {
                        cancelLayerNoRefreshFn();
                    },700);
                }
            }
            //给一个接口地址提交数据
            return web.doAjax(root.sroreinter.editDiscount,'post',user_data,succCallBack);
        })
    }
})
//初始化客户归属下拉列表
function ascription() {
    var user_data = {}
    var succCallBack = function (data, status, response) {
        if (data.errorCode == "0") {
            var dataInter = data.group;
            var interText = doT.template($("#ascription_bob").text());
            $("#ascription_lsit").html(interText(dataInter));
        }
    };
    return web.doAjax(root.inter.getGroup, 'post', user_data, succCallBack);
}